package com.omesoft.hksnore.me;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;

import com.omesoft.hksnore.R;
import com.omesoft.hksnore.util.data.MySharedPreferencesUtil;
import com.omesoft.hksnore.util.myactivity.MyActivity;
import com.omesoft.hksnore.util.titlebar.MyTitlebarUtil;

/**
 * Created by Omesoft on 2017/3/2.
 */

public class MyDeviceActivity extends MyActivity implements View.OnClickListener{

    private TextView mDeviceName_tv;
    private TextView mSnoreStopSata_tv;
    private Button mShackTest_btn;
    private ImageButton mShackSwitch_ib;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.snore_activity_my_device);
        initTitleBar();
        initView();
    }

    @Override
    protected void initTitleBar() {
        super.initTitleBar();
        MyTitlebarUtil.showTitleName(activity,R.string.device_my_device);
        MyTitlebarUtil.showIbLeft(activity,R.mipmap.back).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }

    @Override
    protected void initView() {
        mDeviceName_tv = (TextView) findViewById(R.id.device_name_tv);
        mShackTest_btn = (Button) findViewById(R.id.device_shack_test_btn);
        mShackTest_btn.setOnClickListener(this);
        mShackSwitch_ib = (ImageButton) findViewById(R.id.device_shack_switch_ib);
        mShackSwitch_ib.setOnClickListener(this);
        mSnoreStopSata_tv = (TextView) findViewById(R.id.devici_snore_stop_sata_tv);
        mDeviceName_tv.setText(R.string.device_name);
        if (MySharedPreferencesUtil.getSwitch(context) == true){
            mShackSwitch_ib.setBackground(getResources().getDrawable(R.mipmap.my_mydivice_switch_on));
            mSnoreStopSata_tv.setText(R.string.device_snore_stop_on);
        }else {
            mShackSwitch_ib.setBackground(getResources().getDrawable(R.mipmap.my_mydivice_switch_off));
            mSnoreStopSata_tv.setText(R.string.device_snore_stop_off);

        }

    }


    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.device_shack_switch_ib:
                if (MySharedPreferencesUtil.getSwitch(context)){
                    mShackSwitch_ib.setBackground(getResources().getDrawable(R.mipmap.my_mydivice_switch_off));
                    mSnoreStopSata_tv.setText(R.string.device_snore_stop_off);
                    MySharedPreferencesUtil.setSwitch(context,false);
                }else{
                    mShackSwitch_ib.setBackground(getResources().getDrawable(R.mipmap.my_mydivice_switch_on));
                    mSnoreStopSata_tv.setText(R.string.device_snore_stop_on);
                    MySharedPreferencesUtil.setSwitch(context,true);

                }
                break;
        }

    }


    }

